﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IFServerDLL.Model;
namespace IFClientDLL
{
    public class UserInstrumentOption
    {
        static UserInstrumentOption()
        {
            ListUserInstrumentOption.Add(new UserInstrumentOption() { DftVolume = 1, PriceUpdown = 1, BuyOrSell = MyEnumDirection.Buy, KeyName = Keys.A });
            ListUserInstrumentOption.Add(new UserInstrumentOption() { DftVolume = 1, PriceUpdown = 1, BuyOrSell = MyEnumDirection.Sell, KeyName = Keys.D });
            ListUserInstrumentOption.Add(new UserInstrumentOption() { DftVolume = 1, PriceUpdown = 0, BuyOrSell = MyEnumDirection.Buy, KeyName = Keys.Z });
            ListUserInstrumentOption.Add(new UserInstrumentOption() { DftVolume = 1, PriceUpdown = 0, BuyOrSell = MyEnumDirection.Sell, KeyName = Keys.C });
            ListUserInstrumentOption.Add(new UserInstrumentOption() { KeyName = Keys.Space, IsOrderCancel = true });
        }
        public MyVariety Variety { get; set; }
        public int PriceUpdown { get; set; }
        public int DftVolume { get; set; }
        public MyEnumDirection BuyOrSell { get; set; }
        public Keys KeyName { get; set; }
        public bool IsOrderCancel { get; set; }
        public static List<UserInstrumentOption> ListUserInstrumentOption = new List<UserInstrumentOption>();
        public static UserInstrumentOption GetOption(string instrument, Keys key)
        {
            
            var x= ListUserInstrumentOption.Where(p => p.KeyName==key).FirstOrDefault();
            x.Variety = MyVariety.GetVarietyByInstrument(instrument);
            return x;
        }
    }

    public class UserCommand
    {
        static UserCommand()
        {


        }


        public UserCommand(string instrument, decimal buyPrice, decimal sellPrice, Keys key)
        {
            _Instrument = instrument;
            var cmd = UserInstrumentOption.GetOption(instrument, key);
            decimal _PriceUpDown = cmd.PriceUpdown * cmd.Variety.OneChangedPrice;
            _DftVolume = cmd.DftVolume;
            _Price = cmd.BuyOrSell == MyEnumDirection.Buy ? buyPrice + _PriceUpDown : sellPrice - _PriceUpDown;
            _BuyOrSell = cmd.BuyOrSell;
            _key = key;
            _IsOrderCancel = cmd.IsOrderCancel;
        }
        private string _Instrument;
        public string Instrument
        {
            get { return _Instrument; }
        }
        private MyEnumDirection _BuyOrSell;
        public MyEnumDirection BuyOrSell
        {
            get { return _BuyOrSell; }
        }
        private decimal _Price;
        public decimal Price
        {
            get { return _Price; }
        }
        private Keys _key;
        private bool _IsOrderCancel;
        public bool IsOrderCancel { get { return _IsOrderCancel; } }
        private int _DftVolume;
        public int DftVolume
        {
            get { return _DftVolume; }
        }
        public override string ToString()
        {
            return "UserCommand Key:" + _key.ToString() + " " + Instrument + " " + _BuyOrSell.ToString() + " " + _Price.ToString();
        }
    }
}
